package com.hongxun.modules.csg.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.AddGroup;
import com.hongxun.common.validator.group.UpdateGroup;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.csg.entity.CPolePitEntity;
import com.hongxun.modules.csg.service.CPolePitService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 隐蔽工程：杆塔坑
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-08-30 15:00:41
 */
@RestController
@RequestMapping("/csg/cpolepit")
public class CPolePitController {
	@Autowired
	private CPolePitService cPolePitService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("mCGuid")!=null&&!query.get("mCGuid").toString().equals(""))
		{
			wheres+=" and  m_c_guid = '" + query.get("mCGuid").toString()+"' ";
		}
		if(query.get("state")!=null&&query.get("state").toString().equals("isdelno")) {
			wheres += " and  p_p_datastate != '删除' ";
		}
        query.put("filterSql",wheres+" ");

		List<CPolePitEntity> cPolePitList = cPolePitService.queryList(query);
		int total = cPolePitService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cPolePitList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}



	@RequestMapping("/select")
	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}

		wheres+=" and  p_p_datastate != '删除' ";
		query.put("filterSql",wheres+" ");
		List<CPolePitEntity> cPolePitEntityList = cPolePitService.queryList(query);
		return R.ok().put("returnlist", cPolePitEntityList);
	}



	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		CPolePitEntity cPolePit = cPolePitService.queryObject(guid);
		
		return R.ok().put("cPolePit", cPolePit);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody CPolePitEntity cPolePit){
		cPolePit.setPPDatastate("新增");
		cPolePitService.save(cPolePit);
		
		return R.ok();
	}

	/**
	 * 新增杆塔坑
	 * @param cPolePit
	 * @return
	 */
	@RequestMapping("/saveNew/{mCGuid}/{pGuid}")
	public R save(@RequestBody CPolePitEntity cPolePit ,
				  @PathVariable("mCGuid") String guid ,
				  @PathVariable("pGuid") String pGuid)
	{
		ValidatorUtils.validateEntity(cPolePit, AddGroup.class);
		cPolePit.setMCGuid(guid);
		cPolePit.setPGuid(pGuid);
		cPolePit.setMCName("杆塔坑");
		cPolePit.setPPDatastate("新增");
		cPolePitService.save(cPolePit);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody CPolePitEntity cPolePit){
		ValidatorUtils.validateEntity(cPolePit, UpdateGroup.class);
		cPolePit.setPPDatastate("修改");
		cPolePitService.update(cPolePit);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		cPolePitService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
